package ccrClasses.layer1.alerts;

import ccrClasses.ICcr;
import ccrClasses.layer2.DateTime;
import ccrClasses.layer2.Description;
import ccrClasses.layer2.Reaction;
import ccrClasses.layer2.Source;
import ccrClasses.layer2.Status;
import ccrClasses.layer2.Type;

/**
 * <Alert> encodes allergies, and currently none of the other types. This is why <Type> is always "Allergy."
 * @author matheus
 *
 */
public class Alert implements ICcr{
	
	public final static String OPEN_TAG = "<Alert>";

	public final static String CLOSE_TAG = "</Alert>";
	
	private DateTime startDateTime;
	
	private DateTime stopDateTime;
	
	private Type type;
	
	private Status status;
	
	private Source source;
	
	private Description description;
	
	private Reaction reaction;

	public Alert(DateTime dateTime, Type type, Status status, Source source,
			Description description, Reaction reaction) {
		super();
		this.startDateTime = dateTime;
		this.type = type;
		this.status = status;
		this.source = source;
		this.description = description;
		this.reaction = reaction;
	}
	
	public Alert(DateTime startDateTime,DateTime stopDateTime, Type type, Status status, Source source,
			Description description, Reaction reaction) {
		super();
		this.startDateTime = startDateTime;
		this.stopDateTime = stopDateTime;
		this.type = type;
		this.status = status;
		this.source = source;
		this.description = description;
		this.reaction = reaction;
	}

	public Alert() {
		super();
	}

	/**
	 * @return the dateTime
	 */
	public DateTime getDateTime() {
		return startDateTime;
	}

	/**
	 * @param dateTime the dateTime to set
	 */
	public void setDateTime(DateTime dateTime) {
		this.startDateTime = dateTime;
	}

	/**
	 * @return the type
	 */
	public Type getType() {
		return type;
	}

	/**
	 * @param type the type to set
	 */
	public void setType(Type type) {
		this.type = type;
	}

	/**
	 * @return the status
	 */
	public Status getStatus() {
		return status;
	}

	/**
	 * @param status the status to set
	 */
	public void setStatus(Status status) {
		this.status = status;
	}

	/**
	 * @return the source
	 */
	public Source getSource() {
		return source;
	}

	/**
	 * @param source the source to set
	 */
	public void setSource(Source source) {
		this.source = source;
	}

	/**
	 * @return the description
	 */
	public Description getDescription() {
		return description;
	}

	/**
	 * @param description the description to set
	 */
	public void setDescription(Description description) {
		this.description = description;
	}

	/**
	 * @return the reaction
	 */
	public Reaction getReaction() {
		return reaction;
	}

	/**
	 * @param reaction the reaction to set
	 */
	public void setReaction(Reaction reaction) {
		this.reaction = reaction;
	}

	/**
	 * @return the oPEN_TAG
	 */
	public String getOPEN_TAG() {
		return OPEN_TAG;
	}

	/**
	 * @return the cLOSE_TAG
	 */
	public String getCLOSE_TAG() {
		return CLOSE_TAG;
	}

	/**
	 * @param stopDateTime the stopDateTime to set
	 */
	public void setStopDateTime(DateTime stopDateTime) {
		this.stopDateTime = stopDateTime;
	}

	/**
	 * @return the stopDateTime
	 */
	public DateTime getStopDateTime() {
		return stopDateTime;
	}

	@Override
	public String constructCcrString() {
		String ccrAlert = OPEN_TAG;
		
		if (this.startDateTime != null) {
			ccrAlert = ccrAlert + this.startDateTime.constructCcrString();
		}

		if (this.stopDateTime != null) {
			ccrAlert = ccrAlert + this.stopDateTime.constructCcrString();
		}

		if (this.type != null) {
			ccrAlert = ccrAlert + this.type.constructCcrString();	
		}
		
		if (this.description != null) {
			ccrAlert = ccrAlert + this.description.constructCcrString();
		}

		if (this.status != null) {
			ccrAlert = ccrAlert + this.status.constructCcrString();
		}

		if (this.source != null) {
			ccrAlert = ccrAlert + this.source.constructCcrString();
		}		

		if (this.reaction != null) {
			ccrAlert = ccrAlert + this.reaction.constructCcrString();
		}
			
		ccrAlert = ccrAlert + CLOSE_TAG;
		
		return ccrAlert;
	}
	
	
}
